package com.angel.web.sys;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.angel.core.util.JsonUtil;
import com.angel.core.util.Pager;
import com.angel.health.SysMessageEmail;
import com.angel.provider.sys.SysManagerMessageProvider;

/**
 * 高亚林
 * 2016年9月20日下午1:09:31
 */

@RequestMapping("/manag/message")
@Controller
public class SysManagerMessageController {

	@Autowired
	private SysManagerMessageProvider provider;
	
	@RequestMapping("/index")
	public String index(SysMessageEmail message,Pager pagers,HttpServletRequest request){
		message.setType(1);
		Pager pager = provider.findAll(message, pagers);
		request.setAttribute("pager", pager);
		return "manag/message";
	}
	
	@RequestMapping("/indexEmail")
	public String indexEmail(SysMessageEmail message,Pager pagers,HttpServletRequest request){
		message.setType(2);
		Pager pager = provider.findAll(message, pagers);
		request.setAttribute("pager", pager);
		return "manag/email";
	}
	
	//批量删除
	@RequestMapping("delete")
	@ResponseBody
	public String delete(String ids){
		int i = provider.delete(ids);
		return JsonUtil.toJson(i);
	}
	
	//删除单个用户
	@RequestMapping("deleteById")
	@ResponseBody
	public String deleteById(SysMessageEmail message){
		int i = provider.deleteById(message);
		return JsonUtil.toJson(i);
	}
	
	//保存
	@RequestMapping("/save")
	@ResponseBody
	public String save(SysMessageEmail message,HttpServletRequest request){
		Map<String, String> map = provider.save(message);
		return JsonUtil.toJson(map);
	}
	
	//根据id获取数据
	@RequestMapping("/edit")
	@ResponseBody
	public String edit(SysMessageEmail message){
		Map<String, Object> emailMessage = provider.findUserById(message);
		return JsonUtil.toJson(emailMessage);
	}
	
	//修改
	@RequestMapping("/update")
	@ResponseBody
	public String update(SysMessageEmail message,HttpServletRequest request){
		Map<String, String> map = provider.update(message);
		return JsonUtil.toJson(map);
	}
}
